13. Intro to psql

Using psql Heading

Intro to psql

ND004 C01 L02 17 Using Psql - Create And Drop

Takeaways

  • psql is an interactive terminal application for connecting and interacting with your local postgres server on your machine.
  • Connect using $ psql <dbname>
  • psql lets you
    • Directly type and execute SQL commands to your database
    • Inspect and preview your database and database tables using psql meta-commands
Protip: type \? into psql to see a list of available commands

Useful basic psql commands

psql <dbname> [<username>]

Starts psql with a connection to dbname. Optionally use another user than current user

In psql:

# \l

List all databases on the server, their owners, and user access levels

# \c <dbname>

Connect to a database named

# \dt

Show database tables

# \d <tablename>

Describe table schema

# \q

Quit psql, return to the terminal

# \?

Get help, see list of available commands

Workspace

This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity , so you may be able to download them there.

Workspace Information:

  • Default file path:
  • Workspace type: jupyter-lab
  • Opened files (when workspace is loaded): n/a